package cn.com.dstz.admin.action;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;
import cn.com.dstz.base.action.BaseAction;

public class FenxiAct extends BaseAction{

	/**
	 * 显示分析
	 * @author 黄阳晨
	 * @throws IOException 
	 */
	public void list() throws IOException{
		String sql = "SELECT f.* from dstzfx f WHERE f.aid=:aid order by f.sendtime desc";
		Map<String,Object> valueMap = new HashMap<String,Object>();
		valueMap.put("aid", aid);
		Map<String,Object> resultMap = this.paginationBySQL(sql, null, valueMap, "");
		List< Map< String, Object >> resultList = ( List< Map< String, Object >>) resultMap.get( "rows" );
		for( Map< String, Object > result : resultList ){
			String content = ( String ) result.get( "content" );
			content = Jsoup.clean( content, Whitelist.none( ) );
			int len = content.length( );
			
			if( len > 60 ){
				content = content.substring( 0, 40 ) + "...";
			}
			result.put( "content", content );
		}
		this.responseToJsonObject(resultMap);
		return ;
	}
	
	
	public String toView(){
		String sql = "select f.* ,a.username as username from dstzfx f,dstzadmin a  where f.adminid=a.id and f.id =:id";
		Map<String,Object> valueMap = new HashMap<String,Object>();
		valueMap.put("id", id);
		Map<String,Object> data = baseService.queryForMap(sql, valueMap);
		getRequest().setAttribute("data", data);
		return "view";
	}
	
	public String toNewView(){
		String sql = "select f.* ,a.username as username from dstzfx f,dstzadmin a  where f.adminid=a.id and f.id =:id";
		Map<String,Object> valueMap = new HashMap<String,Object>();
		valueMap.put("id", id);
		Map<String,Object> data = baseService.queryForMap(sql, valueMap);
		getRequest().setAttribute("data", data);
		return "newview";
	}
	
	private static final long serialVersionUID = 1L;
	private String aid ;
	private String id;
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getAid() {
		return aid;
	}

	public void setAid(String aid) {
		this.aid = aid;
	}
}
